package com.lgw.coupon.controller;

import com.lgw.commons.model.domain.ResultInfo;
import com.lgw.commons.utils.ResultInfoUtil;
import com.lgw.coupon.service.IUserService;
import com.lgw.coupon.vo.AcquireTemplateRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
public class UserServiceController {
    @Autowired
    private IUserService userService;
    @Autowired
    private HttpServletRequest request;

    /**
     * 根据顾客id查找当前可以领取的优惠券模板
     * @param customerId
     * @return
     */
    @GetMapping("/template")
    public ResultInfo findAvailableTemplate(@RequestParam("id")Long customerId){
        return userService.findAvailableTemplate(customerId);
    }

    /**
     * 用户领取优惠券
     * @param acquireTemplateRequest
     * @return
     */
    @PostMapping("/acquire/template")
    public ResultInfo acquireTemplate(@RequestBody AcquireTemplateRequest acquireTemplateRequest){
        return ResultInfoUtil.buildSuccess(request.getServletPath(),userService.acquireCoupon(acquireTemplateRequest));
    }
}
